package com.qmx.qmxapp.okhttp;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

import com.qmx.qmxapp.R;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;

import dmax.dialog.SpotsDialog;

/**
 * @param <T>
 */
public abstract class FSimpleCallBack<T> extends BaseCallback<T> {

    private SpotsDialog mDialog;
    private Context mContext;

    public FSimpleCallBack(Context context) {
        //mDialog = new SpotsDialog(context);
        mContext = context;
    }


    @Override
    public void onRequestBefore(Request request) {
    }

    @Override
    public void onFailure(Request request, IOException e) {
        callOnFail(request, e);
    }

    private void callOnFail(final Request request, final IOException e) {
        Handler mHandler = new Handler(Looper.getMainLooper());
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(mContext, mContext.getString(R.string.sys_network_error), Toast.LENGTH_SHORT).show();
                onFail(request, e);
            }
        });
    }

    @Override
    public void onResponse(Response response) {
    }

    public abstract void onFail(Request request, IOException e);

}
